package com.friend.street.dto;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

public class JsonResult {
	 /**
     * 结果类型:成功或者失败
     */
    private JsonResultType type;
    /**
     * json串中输出的业务逻辑
     */
    private Map<String,Object> items = new HashMap<String,Object>();
    
    private String msg;
    
    public JsonResult(){
    	this.type = JsonResultType.SUCCESS;
    	this.msg = "ok";
    }
    public JsonResult(JsonResultType type){
    	this.type = type;
    }
    
    /**
	 * 增加输出对象
	 * @param key
	 * @param value
	 */
	public void add(String key,Object value){
		this.items.put(key, value);
	}
	
	/**
	 * 减少输出对象
	 * @param key
	 */
	public void remove(String key){
		this.items.remove(key);
	}
	/**
	 * 输出json
	 * @return
	 */
	public String toJson(){
		this.items.put("ret", this.getType().getValue());
		this.items.put("msg", this.getMsg());
		JSONObject json = new JSONObject();
		json.putAll(this.items);
		return json.toString();
	}
	public JsonResultType getType() {
		return type;
	}
	public void setType(JsonResultType type) {
		this.type = type;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	
	
	
    
    

}
